let qiniu = require('qiniu'); // 需要加载qiniu模块的
const router = require('koa-router')()
router.prefix('/api/admin/qiniu')

let config = {
    "AK":"TSlScX_akS5TIpsXlkqHH2gy7Efk-ZaZeg4ZWtta",
    "SK":"X-MGLySWVrWFIQKTn87HWDIBvb3ni4Zm3qwZNKxk",
    "Bucket":"mobile-phone-shell"
}

router.post('/token', async(ctx, next)=> {
    let mac = new auth.digest.Mac(config.AK, config.SK);
    let code = '1',msg = '', data = {};
    let options = {
        scope: config.Bucket,
        expires: 3600 * 24
    };
    let putPolicy =  new qiniu.rs.PutPolicy(options);
    let uploadToken= putPolicy.uploadToken(mac);
    if (uploadToken) {
        code = '0';
        data.uploadToken = uploadToken;
        ctx.body = {code, data, msg}
    } else {
        ctx.body = {code, data, msg}
    }
})

module.exports = router
